package com.network.proxy.adapter;

import com.network.proxy.HttpCall;

import rx.Observable;
import rx.Subscriber;

/**
 * Created by kkmike999 on 2016/06/05.
 */
public class RxCallAdapter<T> implements CallAdapter<Observable<T>> {

	@Override
	public Observable<T> adapt(final HttpCall call) {
		return Observable.create(new Observable.OnSubscribe<T>() {
			@Override
			public void call(Subscriber<? super T> subscriber) {
				try {
					subscriber.onNext((T) call.request());
					subscriber.onCompleted();
				} catch (Exception e) {
					subscriber.onError(e);
				}
			}
		});
	}
}
